package com.corpgovernment.job.controller;

import com.corpgovernment.api.organization.model.org.request.ListJobByConditionRequest;
import com.corpgovernment.api.organization.model.org.response.ListJobByConditionResponse;
import com.corpgovernment.common.base.BaseUserInfo;
import com.corpgovernment.common.base.JSONResult;
import com.corpgovernment.job.controller.vo.job.PageBatchImportErrorLineReqVo;
import com.corpgovernment.job.controller.vo.job.ListUsableJobReqVo;
import com.corpgovernment.job.controller.vo.job.ListUsableJobRespVo;
import com.corpgovernment.job.controller.vo.job.CreateJobReqVo;
import com.corpgovernment.job.controller.vo.job.DeleteJobReqVo;
import com.corpgovernment.job.controller.vo.job.PageBatchImportErrorLineRespVo;
import com.corpgovernment.job.controller.vo.job.PageBatchImportJobRecordReqVo;
import com.corpgovernment.job.controller.vo.job.PageBatchImportJobRecordRespVo;
import com.corpgovernment.job.controller.vo.job.PageJobReqVo;
import com.corpgovernment.job.controller.vo.job.PageJobRespVo;
import com.corpgovernment.job.controller.vo.job.UpdateJobReqVo;
import com.corpgovernment.job.controller.vo.jobtype.CreateJobTypeReqVo;
import com.corpgovernment.job.controller.vo.jobtype.DeleteJobTypeReqVo;
import com.corpgovernment.job.controller.vo.jobtype.ListAllJobTypeRespVo;
import com.corpgovernment.job.controller.vo.jobtype.UpdateJobTypeReqVo;
import com.corpgovernment.job.service.JobService;
import com.corpgovernment.job.service.JobTypeService;
import com.corpgovernment.job.service.batchimportjob.BatchImportJobService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author ldma
 * @date 2024/1/2
 */
@RestController
@Slf4j
@RequestMapping("/jobManage")
public class JobManageController {

    @Autowired
    private JobService jobService;

    @Autowired
    private JobTypeService jobTypeService;

    @Autowired
    private BatchImportJobService batchImportJobService;

    @PostMapping("/createJob")
    public JSONResult<String> createJob(@RequestBody CreateJobReqVo requestParam, BaseUserInfo baseUserInfo) {
        jobService.createJob(requestParam, baseUserInfo);
        return new JSONResult<>("");
    }

    @PostMapping("/deleteJob")
    public JSONResult<String> deleteJob(@RequestBody DeleteJobReqVo requestParam) {
        jobService.deleteJob(requestParam);
        return new JSONResult<>("");
    }

    @PostMapping("/updateJob")
    public JSONResult<String> updateJob(@RequestBody UpdateJobReqVo requestParam, BaseUserInfo baseUserInfo) {
        jobService.updateJob(requestParam, baseUserInfo);
        return new JSONResult<>("");
    }

    @PostMapping("/pageJob")
    public JSONResult<PageJobRespVo> pageJob(@RequestBody PageJobReqVo requestParam) {
        return new JSONResult<>(jobService.pageJob(requestParam));
    }

    @PostMapping("/createJobType")
    public JSONResult<String> createJobType(@RequestBody CreateJobTypeReqVo requestParam) {
        jobTypeService.createJobType(requestParam);
        return new JSONResult<>("");
    }

    @PostMapping("/deleteJobType")
    public JSONResult<String> deleteJobType(@RequestBody DeleteJobTypeReqVo requestParam) {
        jobTypeService.deleteJobType(requestParam);
        return new JSONResult<>("");
    }

    @PostMapping("/updateJobType")
    public JSONResult<String> updateJobType(@RequestBody UpdateJobTypeReqVo requestParam) {
        jobTypeService.updateJobType(requestParam);
        return new JSONResult<>("");
    }

    @PostMapping("/listAllJobType")
    public JSONResult<ListAllJobTypeRespVo> listAllJobType() {
        return new JSONResult<>(jobTypeService.listAllJobType());
    }

    @PostMapping("/batchImportJob")
    public JSONResult<String> batchImportJob(@RequestParam("file") MultipartFile file, BaseUserInfo baseUserInfo) {
        batchImportJobService.batchImportJob(file, baseUserInfo);
        return new JSONResult<>("");
    }

    @PostMapping("/pageBatchImportJobRecord")
    public JSONResult<PageBatchImportJobRecordRespVo> pageBatchImportJobRecord(@RequestBody PageBatchImportJobRecordReqVo requestParam) {
        return new JSONResult<>(batchImportJobService.pageBatchImportJobRecord(requestParam));
    }

    @PostMapping("/pageBatchImportErrorLine")
    public JSONResult<PageBatchImportErrorLineRespVo> pageBatchImportErrorLine(@RequestBody PageBatchImportErrorLineReqVo requestParam) {
        return new JSONResult<>(batchImportJobService.pageBatchImportErrorLine(requestParam));
    }

    @PostMapping("/downloadJobTemplateExcel")
    public JSONResult<String> downloadJobTemplateExcel() {
        return new JSONResult<>(batchImportJobService.downloadJobTemplateExcel());
    }

    @PostMapping("/listUsableJob")
    public JSONResult<ListUsableJobRespVo> listUsableJob(@RequestBody ListUsableJobReqVo listUsableJobReqVo, BaseUserInfo baseUserInfo) {
        return new JSONResult<>(jobService.listUsableJob(listUsableJobReqVo, baseUserInfo));
    }

    @RequestMapping("/listJobByCondition")
    public JSONResult<ListJobByConditionResponse> listJobByCondition(@RequestBody ListJobByConditionRequest request, BaseUserInfo baseUserInfo){
        return JSONResult.success(jobService.listJobByCondition(request, baseUserInfo));
    }
}
